#! /bin/bash
# author: 我的代码温柔如风

echo "=================================================="
echo "1、依赖处理"
echo "=================================================="
# 拉取依赖镜像
mysql=mysql:latest

# 检查拉取
chmod +x ../../func_lib.sh
source ../../func_lib.sh
pullIfNotExist ${mysql};

# 启动MySQL
docker run -d \
  -p 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=123456 \
  -e MYSQL_USER=exampleuser \
  -e MYSQL_PASSWORD=examplepass \
  -e MYSQL_DATABASE=exampledb \
  --name=mysql-wp \
  ${mysql}

echo "=================================================="
echo "2、目标处理"
echo "=================================================="

# 设置目标镜像
wordpress=wordpress:latest

# 检查拉取
chmod +x ../../func_lib.sh
source ../../func_lib.sh
pullIfNotExist ${wordpress};

# 启动WordPress
docker run -d \
  -p 8080:80 \
  -e WORDPRESS_DB_HOST=db \
  -e WORDPRESS_DB_USER=exampleuser \
  -e WORDPRESS_DB_PASSWORD=examplepass \
  -e WORDPRESS_DB_NAME=exampledb \
  -e WORDPRESS_TABLE_PREFIX=wp_ \
  -v wordpress:/var/www/html \
  --link mysql-wp:db \
  --name=wordpress \
  ${wordpress}

echo "=================================================="
echo "3、完成"
echo "=================================================="
